package com.yzj.Controller;

import com.netflix.hystrix.contrib.javanica.annotation.HystrixCommand;
import com.yzj.pojo.Emp;
import com.yzj.service.EmpService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Date;
import java.util.Map;

@RestController
public class EmpController {
    @Autowired
    private EmpService es;
    @HystrixCommand(fallbackMethod = "fallback")
    @GetMapping("/hello/{name}")
    public String hello(@PathVariable(value = "name") String name){
        System.out.println("provider:"+name+new Date());
       if (name.equals("admin")){
            int i=10/0;
        }
        return es.hello(name);
    }
    public String fallback(String name){
        System.out.println(name+"不能用");
        return name+"不可用";
    }
    @PostMapping("/selectOne")
    private Emp selectOne(Emp emp){
        System.out.println("provider:"+emp+new Date());
        return es.login(emp);
    }
    @PostMapping("/map")
    private Map<String,Object> map(@RequestParam Map<String,Object> map){
        return es.map(map);
    }

}
